;
(function() {
  var chart = null;
  var industryData = new Vue({
    el:'#origin',
    data(){
      return{
        industryDate:''
      }
    },
    methods: {
      selectOriginDate(){
        industry.data(industry.industryArr)
      }
    },
  })

  var industry = {
    init: function() {
      this.date()
      this.industryType()
      this.selectDate()
    },
    industryArr: [],
    ///获取行业
    industryType: function () {
      var self = this;
      hlhttp.get({
        url: 'configure/dict',
        data: {module_code: 'ZHSH', config_name: 'ZS_CHANNEL_CATE'},
        success: (res) => {
          self.industryArr = res;
          self.data(self.industryArr)
        }
      })
    },
    //统计行业出租面积分布
    data: function(res) {
      var industryArr = res;
      var data = {
        date:industryData.industryDate
      }
      var self = this;

      hlhttp.get({
        url: 'report/customer_by_channel',
        data: data,
        success: function(data) {
          if (!data.length) {
            $('.origin-nodata').show()
            $('.origin-container').html('')
            return
          } else {
            $('.origin-nodata').hide()
          }
          var arr = [],
            total = 0;

          for (var i = 0; i < data.length; i++) {
            let result = '';
            industryArr.map(item => {
              if (item.dictCode == data[i].channel) {
                arr.push([
                  item.dictName,
                  Number(data[i].count)
                ])
              }
            })

            total += data[i].count
          }
          self.charts(arr, total)
        }
      })
    },
    //今天日期
    date: function() {
      function GetDateStr(AddDayCount) {
        var dd = new Date();
        dd.setDate(dd.getDate() + AddDayCount); //获取AddDayCount天后的日期
        var y = dd.getFullYear();
        var m = dd.getMonth() + 1; //获取当前月份的日期
        var d = dd.getDate();
        return y + "-" + tzero(m) + "-" + tzero(d);
      }
      industryData.industryDate = GetDateStr(-1)
    },
    //根据时间选择柱形图
    selectDate: function() {
      var self = this;
      $('.dt-dateControl').unbind().on('click', '.day-item', function(event) {
        if (window.location.hash.indexOf('#/zsAnalysis') >= 0) {

          console.log('22');

          setTimeout(function() {
            self.data(self.industryArr)
          }, 200);
        }

      });
    },
    //charts
    charts: function(data, count) {
      $(function() {
        $('.origin-container').highcharts({
          chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false,
            spacing: [0, 0, 0, 0]
          },
          colors: [
            '#F8D86A ',
            '#7FC684',
            '#69C8FF',
            '#B6F8DA'
          ],
          title: {
            floating: true,
            useHTML: true,
            style: {
              color: '#333',
              fontWeight: '100',
              top: '50%',
              left: '50%',
              transform: 'translate(0,-40%)',
              textAlign: 'center'
            },
            text: '总客户数<p style="font-size:48px;color:#565E99;">' + count + '</p>'
          },
          tooltip: {
            shared: true,
            enabled: true,
            useHTML: true,
            valueDecimals: 2,
			padding: 0,
            headerFormat: '<span class="font-size:14px">{point.key}</span>',
            pointFormat: '{point.y:.1f}({point.percentage:.2f}%)',
            borderWidth: 0,
            style: {
              fontSize: '14px'
            }
          },
          plotOptions: {
            pie: {
              enabled: true,
              cursor: 'pointer',
              borderWidth:2,
              dataLabels: {
                shared: true,
                useHTML: true,
                valueDecimals: 2,
                enabled: false,
                format: '<b>{point.name}</b>: {point.y:.1f}({point.percentage:.2f}%)',
                style: {
                  color: '#666',
                  fontFamily: 'Microsoft Yahei',
                  fontSize: '14px'
                }
              },
			  showInLegend: true
            }
          },
          series: [
            {
              type: 'pie',
              innerSize: '60%',
              name: ' ',
              data: data
            }
          ]
        }, function(c) {
          // 环形图圆心
          var centerY = c.series[0].center[1],
            titleHeight = parseInt(c.title.styles.fontSize);
          c.setTitle({
            y: centerY + titleHeight / 2
          });
          chart = c;
        });
      });
    }
  }
  industry.init()

  function tzero(n) {
    return n < 10
      ? '0' + n
      : '' + n
  }






}())
